//
//  LoginViewController.m
//  Tongcheng
//
//  Created by 邢广范 on 2017/4/3.
//  Copyright © 2017年 Tongcheng. All rights reserved.
//账号密码登录界面

#import "LoginViewController.h"
#import "LoginModel.h"
#import "LoginDataModel.h"
#import "LoginOperator.h"
#import "AppDelegate.h"
#import "CheckUtils.h"

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
- (IBAction)loginBtnClick:(id)sender;

@end

@implementation LoginViewController

- (void)setupNavigation
{
    self.navigationItem.title = @"用户登录";
}

- (void)setupView
{
    self.userNameTextField.text = self.config.userName;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigation];
    [self setupView];
    // Do any additional setup after loading the view from its nib.
}

//点击登录
- (IBAction)loginBtnClick:(id)sender {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"user_login"] = self.userNameTextField.text;
    dic[@"user_pass"] = self.passwordTextField.text;
    LoginOperator *operator = [[LoginOperator alloc] initWithParams:dic];
    [self.networkingManager asyncTaskOnVC:self operator:operator successBlock:^(BaseModel *baseModel) {
        if ([baseModel.code isEqualToString:@"1"]) {
            self.config.userId = operator.data.data.user_id;
            self.config.token = operator.data.data.token;
            self.config.userName = self.userNameTextField.text;
            AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
            [delegate choosViewController];
        }
        [self showToastMessage:baseModel.msg];
    } failBlock:^(BaseModel *baseModel) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
